const http = require('../../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navindex: 0,
    taberArr: [],
    history: [],
    page: 0,
    id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    http.postRequest('/mini/v1/work/base_data',{},res=> {
      res.data.profession_cate.unshift({id: '', name: '全部'})
      this.setData({
        taberArr: res.data.profession_cate
      })
    })
    http.postRequest('/mini/v1/car_owner/purchase_history',{owner_id: options.id},res=> {
      this.setData({
        history: res.data
      })
    })
  },
  // 底部加载
  onReachBottom() {
    let page = this.data.page;
    if(this.data.page <= this.data.history.last_page) {
      page++;
      this.setData({
        page: page
      })
      this.getData('',page);
    }
  },
  getData(profession_cate_id,page,per_page) {
    http.postRequest('/mini/v1/car_owner/purchase_history',{owner_id: this.data.id,profession_cate_id: profession_cate_id,page: page,per_page:per_page},res=> {
      this.setData({
        history: res.data
      })
    })
  },
  navindex(e) {
    let index = e.currentTarget.dataset.index;
    let id = e.currentTarget.dataset.id;
    this.setData({
      navindex: index
    })
    this.getData(id, '',100);
  }
})